package com.ym.controller.medical;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ym.common.utils.page.PageDomain;
import com.ym.medical.domain.entity.SubjectReplyEntity;
import com.ym.medical.domain.vo.SubjectReplyListPcVO;
import com.ym.medical.domain.param.SubjectReplyQueryParam;
import com.ym.medical.domain.param.SubjectReplyUpdateParam;
import com.ym.medical.service.ISubjectReplySV;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.Valid;

/**
 * 主题回复Controller
 * 
 * @author ym
 * @date 2020-08-24
 */
@Api(tags = "medical-主题回复")
@RestController("SubjectReplyPcController")
@Validated
@RequestMapping("/medical/reply")
public class SubjectReplyController extends BaseController {

    @Autowired
    private ISubjectReplySV subjectReplySV;

    @ApiOperation("查询主题回复列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<SubjectReplyListPcVO>> list(@Valid SubjectReplyQueryParam queryParam) {
        PageDomain.startPage();
        List<SubjectReplyListPcVO> list = subjectReplySV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取主题回复详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<SubjectReplyEntity> info(@RequestParam Long id) {
        SubjectReplyEntity data = subjectReplySV.selectById(id);
        return successData(data);
    }

    @ApiOperation("新增主题回复")
    @Log(printQuery = false)
    @PostMapping("/insert")
    public APIResponse insert(@RequestBody @Validated(value = Add.class) SubjectReplyUpdateParam updateParam) {
        Long id = subjectReplySV.insertPC(updateParam);
        return successData(id);
    }

    @ApiOperation("修改主题回复")
    @Log(printQuery = false)
    @PostMapping("/update")
    public APIResponse update(@RequestBody @Validated(value = Update.class) SubjectReplyUpdateParam updateParam) {
        int result = subjectReplySV.updateByIdPC(updateParam);
        return successData(result);
    }

    @ApiOperation("删除主题回复")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        int result = subjectReplySV.deleteByIds(ids);
        return successData(result);
    }
}
